import React, { useState } from 'react';
import { Modal, Menu } from 'antd';
import { history } from 'umi';
import { LockOutlined, PoweroffOutlined, ExclamationCircleFilled } from '@ant-design/icons';
import cookit from '../../Control/cookie'
import { userLogout } from '../../api/request';

const { confirm } = Modal;

function userMunu (props){


    const logout = ()=>{
        confirm({
            title: '确认退出此账号?',
            icon: <ExclamationCircleFilled style={{color:"#e76609"}}/>,
            cancelText:'取消',
            okText:'确认',
            onOk() {
                userLogout().then(res=>{
                    console.log(res);
                    if(res){
                        cookit.unsetAll()
                        history.push('/');
                    }
                })
            }
        });
    }

    return (
        <Menu>
            <Menu.Item>
                {props.userAccount}
            </Menu.Item>
            <Menu.Item>
                <LockOutlined />
                修改密码
            </Menu.Item>
            <Menu.Item onClick={()=>logout()}>
                <PoweroffOutlined />
                退出登录
            </Menu.Item>
        </Menu>
    )
}
export default userMunu;